package com.oazon.moco.link.core;

import java.util.Arrays;
import java.util.EventListener;
import java.util.List;

import com.oazon.moco.link.core.source.LinkEventSource;

/**
 * LinkEvent事件监听类
 * 
 * @author chengke
 *
 */
public abstract class LinkEventListener implements EventListener {

	private List<LinkEventSource> blackList;
	
	public List<LinkEventSource> getBlackList() {
		return blackList;
	}

	public void setBlackList(List<LinkEventSource> blackList) {
		this.blackList = blackList;
	}

	public LinkEventListener(List<LinkEventSource> blackList) {
		this.blackList = blackList;
	}

	public LinkEventListener() {

	}
	
	public LinkEventListener(LinkEventSource...blackSources) {
		this.blackList = Arrays.asList(blackSources);
	}


	/**
	 * 
	 * @param source
	 * @return 
	 * 		true 在黑名单中,则不通知
	 * 
	 */
	public boolean filter(LinkEventSource source){
		if(source == null ||blackList == null){
			return false;
		}
		for(LinkEventSource s : blackList){
			if(source.getClass() == s.getClass()){
				return true;
			}
		}
		return false;
	}
	
	abstract public void onLinkEvent(LinkEvent event);

}